#include <iostream>
#include <fstream>
#include <string>
#include <vector>

using namespace std;

int zFunc(const string& subString, const string& text) {
    int subStringLength = subString.length(), end = text.length() + subStringLength + 1;
    vector<int> Z(end);
    Z[0] = end;

    int r = 1;
    for (int i = 1; i < end; ++i) {
        Z[i] = 0;
        if (i == subStringLength) 
            continue;
        if (r + Z[r] - 1 > i) {
            if (Z[i - r] < r + Z[r] - i) {
                Z[i] = Z[i - r];
            } else {
                int k = r + Z[r] + Z[i];
                while (k < end && k != subStringLength && k - i != subStringLength) {
                    if (k < subStringLength && subString[k - i] != subString[k] || k - i < subStringLength && k > subStringLength && subString[k - i] != text[k - subStringLength - 1]) 
                        break;
                    ++Z[i];
                    ++k;
                }
                Z[i] += r + Z[r] - i;
                r = i;
            }
        } else {
            while (i + Z[i] < end && i + Z[i] != subStringLength) {
                if (i + Z[i] < subStringLength && subString[Z[i]] != subString[i + Z[i]] || i + Z[i] > subStringLength && subString[Z[i]] != text[i + Z[i] - subStringLength - 1]) 
                    break;
                ++Z[i];
            }
            r = i;
        }
        if (Z[i] == subStringLength && i > subStringLength)
            return i - subStringLength - 1;
    }
    return -1;
}

int prefixFunc(const string& subString, const string& text) {
    int subStringLength = subString.size();
    vector<int> P(subStringLength);
    P[0] = 0;

    for (int i = 1; i < subStringLength; ++i) {
        int k = P[i-1];
        while (k > 0 && subString[i] != subString[k]) 
            k = P[k - 1];
        if (subString[i] == subString[k]) 
            ++k;
            P[i] = k;
    }

    int k = 0;
    for (size_t i = 0; i < text.size(); ++i) {
        while (k > 0 && subString[k] != text[i]) 
            k = P[k - 1];
        if (subString[k] == text[i]) 
            ++k;
        if (k == subStringLength) {
            return i - subStringLength + 1;
        }
    }
    return -1;
}

int main()
{
    ifstream ifile("in.txt");
    string text;
    if (getline(ifile, text)) {
        string subString;
        while (getline(ifile, subString)) {
            if(!subString.empty()) {
                cout << zFunc(subString, text) << endl;
                cout << prefixFunc(subString, text) << endl;
            }                
        }
    }
    ifile.close();
    return 0;
}